﻿Imports System.Data
Imports FirebirdSql.Data.FirebirdClient
Public Class _Autentica
    Inherits _DataBase

    Private _Login As String
    Private _Senha As String
    Private _nmCompleto As String
    Private _idPerfil As Integer
    Private _dsPerfil As String
    Private _Msg As String

    Private _idUsuario As Integer
    Public Property idUsuario() As Integer
        Get
            Return _idUsuario
        End Get
        Set(ByVal value As Integer)
            _idUsuario = value
        End Set
    End Property


    Public Property Login() As String
        Get
            Return _Login
        End Get
        Set(ByVal value As String)
            _Login = value
        End Set
    End Property

    Public Property Senha() As String
        Get
            Return _Senha
        End Get
        Set(ByVal value As String)
            _Senha = value
        End Set
    End Property

    Public Property NmCompleto() As String
        Get
            Return _nmCompleto
        End Get
        Set(ByVal value As String)
            _nmCompleto = value
        End Set
    End Property
    Public Property idPerfil()
        Get
            Return _idPerfil
        End Get
        Set(ByVal value)
            _dsPerfil = value
        End Set
    End Property

    Public Property dsPerfil() As String
        Get
            Return _dsPerfil
        End Get
        Set(ByVal value As String)
            _dsPerfil = value
        End Set
    End Property

    Public Property Msg() As String
        Get
            Return _Msg
        End Get
        Set(ByVal value As String)
            _Msg = value
        End Set
    End Property

    Public Function autenticaUsuarioSenha(ByVal plogin As String, ByVal psenha As String) As Boolean
        Login = plogin
        Senha = psenha
        conectaDb()
        dr = retornaDataReader(montaParametroSQL("SP_USUARIOSISTEMA_CONSULTA", "VALIDAR"))
        Try
            With dr
                If .Read Or .RecordsAffected > 0 Then
                    Login = .Item("O_LOGIN")
                    idUsuario = .Item("O_ID_USUARIO")

                    NmCompleto = .Item("O_NM_COMPLETO")
                    idPerfil = .Item("O_ID_PERFILUSUARIO")
                    dsPerfil = .Item("O_DS_PERFIL")
                    desconectaDb()
                    Return True
                Else
                    desconectaDb()
                    Return False

                End If
            End With
        Catch ex As Exception

        End Try




    End Function

    Public Sub insereUsuario()
        conectaDb()
        execSQLSemRetorno(montaParametroSQL("SP_USUARIOSISTEMA_CMD", "INSERIR"))
        desconectaDb()
    End Sub

    Private Function montaParametroSQL(ByVal nomeSP As String, ByVal pModo As String) As FbCommand
        With cmd
            .CommandText = nomeSP
            With .Parameters
                .Clear()
                .Add("MODO", FbDbType.VarChar, 20).Value = pModo
                .Add("I_LOGIN", FbDbType.Integer).Value = Login
                .Add("I_SENHA", FbDbType.Integer).Value = Senha
                .Add("I_NM_COMPLETO", FbDbType.Integer).Value = idUsuario
                .Add("I_ID_USUARIO", FbDbType.Integer).Value = idUsuario
                .Add("I_ID_PERFIL", FbDbType.Integer).Value = idUsuario
          
            End With
        End With
        Return cmd

    End Function
 
  
End Class
